package com.zwxbc.funplay.service.impl;

import com.zwxbc.funplay.dao.GameCommentDao;
import com.zwxbc.funplay.dao.impl.GameCommentDaoImpl;
import com.zwxbc.funplay.entity.GameComment;
import com.zwxbc.funplay.entity.Player;
import com.zwxbc.funplay.service.GameCommentService;
import com.zwxbc.funplay.service.PlayerService;

import java.util.List;

/**
 * @author Liubuzhu
 */
public class GameCommentServiceImpl implements GameCommentService {
	GameCommentDao gameCommentDao = new GameCommentDaoImpl();
	PlayerService playerService = new PlayerServiceImpl();

	@Override
	public List<GameComment> getGameCommentList() {
		List<GameComment> allGameComments = gameCommentDao.getAllGameComments();
		for (GameComment gameComment : allGameComments) {
			Player player = playerService.getPlayerById(gameComment.getPlayerId());
			if ( player!= null) {
				gameComment.setPlayerName(player.getPlayerName());
				gameComment.setPlayerImage(player.getPlayerImage());
			}
		}
		return allGameComments;
	}

	@Override
	public boolean deleteGameComment(Long gameCommentId) {
		int result = gameCommentDao.deleteGameComment(gameCommentId);
		return result > 0;
	}

	@Override
	public boolean updateGameComment(GameComment GameComment) {
		int result = gameCommentDao.updateGameComment(GameComment);
		return result > 0;
	}

	@Override
	public boolean addGameComment(GameComment gameComment) {
		int result = gameCommentDao.addGameComment(gameComment);
		return result > 0;
	}

	@Override
	public List<GameComment> getGameCommentListByGameId(Long gameCommentCategoryId) {
		List<GameComment> allGameComments = gameCommentDao.getGameCommentListByGameId(gameCommentCategoryId);
		for (GameComment gameComment : allGameComments) {
			Player player = playerService.getPlayerById(gameComment.getPlayerId());
			if ( player!= null) {
				gameComment.setPlayerName(player.getPlayerName());
				gameComment.setPlayerImage(player.getPlayerImage());
			}
		}
		return allGameComments;
	}

	@Override
	public GameComment getGameCommentById(Long gameCommentId) {
		GameComment gameCommentById = gameCommentDao.getGameCommentById(gameCommentId);
		Player player = playerService.getPlayerById(gameCommentById.getPlayerId());
		if ( player!= null) {
			gameCommentById.setPlayerName(player.getPlayerName());
			gameCommentById.setPlayerImage(player.getPlayerImage());
		}
		return gameCommentById;
	}
}
